# 示例1: 过滤出偶数
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# 使用 filter
even_numbers = filter(lambda x: x % 2 == 0, numbers)
print(list(even_numbers))  # [2, 4, 6, 8, 10]

# 等价于列表推导式
even_numbers = [x for x in numbers if x % 2 == 0]
print(even_numbers)  # [2, 4, 6, 8, 10]


# 示例1: 将列表中的每个数字平方
numbers = [1, 2, 3, 4, 5]

# 使用 map
squared = map(lambda x: x ** 2, numbers)
print(list(squared))  # [1, 4, 9, 16, 25]

# 等价于列表推导式
squared = [x ** 2 for x in numbers]
print(squared)  # [1, 4, 9, 16, 25]

from functools import reduce

# 示例1: 计算乘积
numbers = [1, 2, 3, 4, 5]

product = reduce(lambda x, y: x * y, numbers)
print(product)  # 120
# 计算过程: ((((1×2)×3)×4)×5) = 120

# 示例2: 找出最大值
max_number = reduce(lambda x, y: x if x > y else y, numbers)
print(max_number)  # 5